<link rel="stylesheet" href="<{$style_dir}>/css/common.css" />
<link rel="stylesheet" href="<{$style_dir}>/css/community.css" />
<link rel="stylesheet" href="<{$style_dir}>/css/icon.css" />
<script src="<{$style_dir}>/js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8" src="<{$style_dir}>/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="<{$style_dir}>/ueditor/ueditor.all.min.js"> </script>
<script src="/static/public/layer.js" type="text/javascript" charset="utf-8"></script>
<div class="mt20 plr50">
    <div class="post-article fl w600">
        <{if in_array(1,$task['validate'])}>
        <div class="title mt20" id="task_name">
            <p class="title-big">姓名</p>
            <div class="title-box">
                <input type="text" name="name" value="<{$validate['name']}>" id="post_name" autofocus/>
            </div>
        </div>
        <script>
            var task_name = 1;
        </script>
        <{/if}>
        <{if in_array(2,$task['validate'])}>
        <div class="title mt20" id="task_identity">
            <p class="title-big">身份证</p>
            <div class="title-box">
                <input type="text" name="identity" value="<{$validate['identity']}>" id="post_identity" onkeyup="this.value=this.value.replace(/\D/g,'')"/>
            </div>
        </div>
        <script>
            var task_identity = 1;
        </script>
        <{/if}>
        <{if in_array(3,$task['validate'])}>
        <div class="title mt20" id="task_phone">
            <p class="title-big">手机号码</p>
            <div class="title-box">
                <input type="text" name="phone" value="<{$validate['phone']}>" id="post_phone" onkeyup="this.value=this.value.replace(/\D/g,'')"/>
            </div>
        </div>
        <script>
            var task_phone = 1;
        </script>
        <{/if}>
        <style>
            .ht_ul{
                width: 100%;
                height: auto;
            }
            .ht_ul li{
                border: 1px solid #e5e5e5;
                margin-right: 10px;
            }
        </style>
        <div class="title mt20" id="imgdemo_list">
            <p class="title-big">截图示例</p>
            <ul class="ht_ul">
                <{if $task['img_list']}>
                <{foreach from=$task['img_list'] item=imgval}>
                <li style="float: left;"><img src="<{$imgval}>" width="200"><input type="hidden" name="task_demoimglist[]" value="<{$imgval}>"/> </li>
                <{/foreach}>
                <div class="clear"></div>
                <{/if}>
            </ul>
        </div>
        <div class="title mt20" id="img_list">
            <div class="wd-content" style="width: 130px;">
                <div class="wd-operate" style="width: 90px;">
                    <a href="javascript:void(0);" onclick="upImage();"><b class="icon-com icon-adphoto"></b>添加图片</a>
                    <input class="easyui-textbox" type="hidden" id="picture" name="pic" value="" style="width:160px"/>
                </div>
            </div>

            <ul class="ht_ul" id="preview">
                <{if $validate['img_list']}>
                <{foreach from=$validate['img_list'] item=vimgval}>
                <li style="float: left;"><img src="<{$vimgval}>" width="200"><input type="hidden" name="task_imglist[]" value="<{$vimgval}>"/> </li>
                <{/foreach}>
                <div class="clear"></div>
                <{/if}>
            </ul>
            <i class="mt5"></i>
        </div>

        <div class="post-btn mt20">
            <input type="hidden" value="<{$task['tid']}>" id="post_tid"/>
            <input class="release fr ml20 _T_post_publish" type="submit" value="确认提交" data-action-url="<{eval url('task/submit_validate')}>" data-unvalid="提交中..."/>
        </div>

        <script id="Ueditor" type="text/plain"></script>
        <script>
            var _editor = UE.getEditor('Ueditor');
            _editor.ready(function () {
                //设置编辑器不可用
                //_editor.setDisabled();  //这个地方要注意 一定要屏蔽
                //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
                _editor.hide();
                //侦听图片上传
                _editor.addListener('beforeinsertimage', function (t, arg) {
                    //将地址赋值给相应的input,只去第一张图片的路径
                    var imgs,imagehtml='';
                    for(var a in arg){
                        imagehtml += '<li style="float: left;"><img src="'+arg[a].src+'" alt="'+arg[a].alt+'" width="200"><input type="hidden" name="task_imglist[]" value="'+arg[a].src+'"/> </li>';
                    }
                    imagehtml += '<div class="clear"></div>';

                    //图片预览
                    $("#preview").append(imagehtml);
                })

            });
            //弹出图片上传的对话框
            function upImage() {
                var myImage = _editor.getDialog("insertimage");
                myImage.open();
            }
            var _T_post_publish_btn = $("._T_post_publish");

            _T_post_publish_btn.on("click", function () {
                var _imglist = $("input[name='task_imglist[]']").map(function () {return $(this).val();}).get();
                var _self = $(this),
                    _name = $.trim($("#post_name").val()),
                    _identity = $.trim($("#post_identity").val()),
                    _phone = $.trim($("#post_phone").val()),
                    _tid = $.trim($("#post_tid").val()),
                    params = {},_url = _self.attr("data-action-url");
                if(!_name && typeof task_name!="undefined"){layer.msg("姓名不能为空哦",{icon:0,time:2000,shift:6,offset:300});return;}
                if(!_identity && typeof task_identity!="undefined"){layer.msg("身份证号不能为空哦",{icon:0,time:2000,shift:6,offset:300});return;}
                if(!_phone && typeof task_phone!="undefined"){layer.msg("手机不能为空哦",{icon:0,time:2000,shift:6,offset:300});return;}
                params.name = _name;
                params.identity = _identity;
                params.phone = _phone;
                params.tid = _tid;
                params.img_list = _imglist;

                $.ajax({
                    url: _url,
                    type: "post",
                    dataType: "json",
                    data: params,
                    success: function(data) {
                        layer.msg(data.msg,{
                            icon: 1,
                            time: 2000
                        }, function(){
                            parent.location.href=data.link;
                        });
                    }
                });
            });
        </script>
    </div>
</div>